<?php 
header("Content-Type:text/html;charset=utf-8");
session_start();
include "includes/init.php";
$id=isset($_SESSION['id'])?$_SESSION['id']: null ;
$phone=isset($_SESSION['phone'])?$_SESSION['phone']: null ;

// 项目
$sql ="select distinct p.project from t_product as p, t_bid as b  where b.mid = '".$id."' and b.btype = p.type order by pid asc";
$result = $db_Obj ->getall($sql);
 // 型号
$sql="select distinct p.type from t_product p left join t_bid b on b.btype=p.type where b.mid = '".$id."' ";
$needall=$db_Obj->getall($sql);

if(!empty($_POST)){

    $type=isset($_POST['stype'])?$_POST['stype']: null ;
    $start=isset($_POST['start'])?strtotime($_POST['start']): null ;
    $end=isset($_POST['end'])?strtotime($_POST['end']): null ;
    $project = isset($_POST['project']) ? $_POST['project']:  null ;   

    if($type != null ){
    	$where =" p.type='".$type."'";
    }

    if($project !=  null ){
    	if(empty($where)){
    		$where = " p.project = '".$project."' ";
    	}else{
	    	$where.=" and p.project = '".$project."' ";
    	}
    }
    if ($start!= null && $end!= null ) {
    	if(empty($where)){
    		$where = " b.createtime between $start and $end ";
    	}else{
	    	$where.=" and b.createtime between $start and $end ";
    	}
    }

    $sql="select p.status,p.project,p.units,b.rate,p.currency,p.material,
            p.purchase,
            p.plant,
            p.extranum, p.type,p.size,b.delivery,b.MOQ,b.MPQ,p.number,b.createtime,b.price from t_product p left join t_bid b on b.btype=p.type where b.mid = '".$id."' and {$where}";
    // echo $sql;
    $infoall=$db_Obj->getall($sql);
}


// 导出Excel 
if(!empty($_POST['export'])){
	$export = $_POST['export'];
}
 if ($export == 1) {
 	 foreach ($infoall as $k =>$v) {
      	$infoall[$k]['createtime']=date('Y-m-d H:i:s',$v['createtime']);
      }
       
        $columns = array(
        	array(
                'title' => '项目',
                'field' => 'project',
                'width' => 20
            ),
            array(
                'title' => '型号',
                'field' => 'type',
                'width' => 20
            ),
            array(
                'title' => '物料编码',
                'field' => 'size',
                'width' => 10
            ),
            array(
                'title' => '数量',
                'field' => 'number',
                'width' => 10
            ),
            array(
                'title' => '单位',
                'field' => 'units',
                'width' =>10
            ),
            array(
                'title' => '价位',
                'field' => 'price',
                'width' =>10
            ),
            array(
                'title' => '税率',
                'field' => 'rate',
                'width' =>10
            ),
            array(
                'title' => '币种',
                'field' => 'currency',
                'width' =>10
            ),
            array(
                'title' => '交期',
                'field' => 'delivery',
                'width' =>10
            ),
            array(
                'title' => 'MOQ',
                'field' => 'MOQ',
                'width' =>10
            ),
            array(
                'title' => 'MPQ',
                'field' => 'MPQ',
                'width' =>10
            ),
            array(
				'title' => '报价时间',
                'field' => 'createtime',
                'width' =>20
            	)

        );
        $exportlist =$infoall;
     
       $excObj->export($exportlist, array(
            "title" => "数据-" . date('Y-m-d-H-i', time()),
            "columns" => $columns
        ));
    }

include 'table5.html';